{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "view-in-github"
   },
   "source": [
    "<a target=\"_blank\" href=\"https://colab.research.google.com/github/AI4Finance-Foundation/FinRL-Tutorials/blob/master/2-Advance/stock_wrds.ipynb\">\n",
    "  <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
    "</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "c1gUG3OCJ5GS"
   },
   "source": [
    "# **Stock Trading Using WRDS Data in NeoFinRL**\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "DbamGVHC3AeW"
   },
   "source": [
    "# **Part 1: Install NeoFinRL, ElegantRL and related packages**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "U35bhkUqOqbS",
    "outputId": "c1ea49f1-e915-480a-de58-44f843b5bf9d"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting git+https://github.com/AI4Finance-LLC/NeoFinRL.git\n",
      "  Cloning https://github.com/AI4Finance-LLC/NeoFinRL.git to /tmp/pip-req-build-l5n5ubce\n",
      "  Running command git clone -q https://github.com/AI4Finance-LLC/NeoFinRL.git /tmp/pip-req-build-l5n5ubce\n",
      "Requirement already satisfied: gym in /usr/local/lib/python3.7/dist-packages (from neofinrl==0.0.1) (0.17.3)\n",
      "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from neofinrl==0.0.1) (1.19.5)\n",
      "Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from gym->neofinrl==0.0.1) (1.4.1)\n",
      "Requirement already satisfied: cloudpickle<1.7.0,>=1.2.0 in /usr/local/lib/python3.7/dist-packages (from gym->neofinrl==0.0.1) (1.3.0)\n",
      "Requirement already satisfied: pyglet<=1.5.0,>=1.4.0 in /usr/local/lib/python3.7/dist-packages (from gym->neofinrl==0.0.1) (1.5.0)\n",
      "Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from pyglet<=1.5.0,>=1.4.0->gym->neofinrl==0.0.1) (0.16.0)\n",
      "Building wheels for collected packages: neofinrl\n",
      "  Building wheel for neofinrl (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
      "  Created wheel for neofinrl: filename=neofinrl-0.0.1-cp37-none-any.whl size=70711 sha256=a6688556d0321e542ba39c3d0f34d017388ab0f17d29fd56c690f03dd300e778\n",
      "  Stored in directory: /tmp/pip-ephem-wheel-cache-08sia8q1/wheels/fa/c0/c9/bf3369bebc879bb6d0f2fbbe67715776c0dc1302dfa94ccd8f\n",
      "Successfully built neofinrl\n",
      "Installing collected packages: neofinrl\n",
      "Successfully installed neofinrl-0.0.1\n",
      "Collecting git+https://github.com/AI4Finance-LLC/ElegantRL.git\n",
      "  Cloning https://github.com/AI4Finance-LLC/ElegantRL.git to /tmp/pip-req-build-txf7lp1l\n",
      "  Running command git clone -q https://github.com/AI4Finance-LLC/ElegantRL.git /tmp/pip-req-build-txf7lp1l\n",
      "Requirement already satisfied: gym in /usr/local/lib/python3.7/dist-packages (from elegantrl==0.3.1) (0.17.3)\n",
      "Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from elegantrl==0.3.1) (3.2.2)\n",
      "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from elegantrl==0.3.1) (1.19.5)\n",
      "Collecting pybullet\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/73/6d/60b97ffc579db665bdd87f2cb47fe1215ae770fbbc1add84ebf36ddca63b/pybullet-3.1.7.tar.gz (79.0MB)\n",
      "\u001b[K     |████████████████████████████████| 79.0MB 67kB/s \n",
      "\u001b[?25hRequirement already satisfied: torch in /usr/local/lib/python3.7/dist-packages (from elegantrl==0.3.1) (1.8.1+cu101)\n",
      "Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (from elegantrl==0.3.1) (4.1.2.30)\n",
      "Collecting box2d-py\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/87/34/da5393985c3ff9a76351df6127c275dcb5749ae0abbe8d5210f06d97405d/box2d_py-2.3.8-cp37-cp37m-manylinux1_x86_64.whl (448kB)\n",
      "\u001b[K     |████████████████████████████████| 450kB 40.5MB/s \n",
      "\u001b[?25hRequirement already satisfied: cloudpickle<1.7.0,>=1.2.0 in /usr/local/lib/python3.7/dist-packages (from gym->elegantrl==0.3.1) (1.3.0)\n",
      "Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from gym->elegantrl==0.3.1) (1.4.1)\n",
      "Requirement already satisfied: pyglet<=1.5.0,>=1.4.0 in /usr/local/lib/python3.7/dist-packages (from gym->elegantrl==0.3.1) (1.5.0)\n",
      "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->elegantrl==0.3.1) (2.8.1)\n",
      "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->elegantrl==0.3.1) (2.4.7)\n",
      "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->elegantrl==0.3.1) (0.10.0)\n",
      "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->elegantrl==0.3.1) (1.3.1)\n",
      "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch->elegantrl==0.3.1) (3.7.4.3)\n",
      "Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from pyglet<=1.5.0,>=1.4.0->gym->elegantrl==0.3.1) (0.16.0)\n",
      "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.1->matplotlib->elegantrl==0.3.1) (1.15.0)\n",
      "Building wheels for collected packages: elegantrl, pybullet\n",
      "  Building wheel for elegantrl (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
      "  Created wheel for elegantrl: filename=elegantrl-0.3.1-cp37-none-any.whl size=65369 sha256=3caa79f25d2076a47334788cc7c477fc18dfe09358d57eeb0511dfc53e508899\n",
      "  Stored in directory: /tmp/pip-ephem-wheel-cache-kys2v32f/wheels/d0/f4/2e/cec0c14b57c2094a2bcef3063f95d758ad1309a640ff100419\n",
      "  Building wheel for pybullet (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
      "  Created wheel for pybullet: filename=pybullet-3.1.7-cp37-cp37m-linux_x86_64.whl size=89751263 sha256=191f1b554312cb9a4586b0eb95f950ea9b163efdf1f81a29ea2d6b1af6d3921e\n",
      "  Stored in directory: /root/.cache/pip/wheels/30/56/e6/fce8276a2f30165f7ac31089bb72f390fa16b87328651e1a5a\n",
      "Successfully built elegantrl pybullet\n",
      "Installing collected packages: pybullet, box2d-py, elegantrl\n",
      "Successfully installed box2d-py-2.3.8 elegantrl-0.3.1 pybullet-3.1.7\n",
      "Collecting yfinance\n",
      "  Downloading https://files.pythonhosted.org/packages/a7/ee/315752b9ef281ba83c62aa7ec2e2074f85223da6e7e74efb4d3e11c0f510/yfinance-0.1.59.tar.gz\n",
      "Collecting stockstats\n",
      "  Downloading https://files.pythonhosted.org/packages/32/41/d3828c5bc0a262cb3112a4024108a3b019c183fa3b3078bff34bf25abf91/stockstats-0.3.2-py2.py3-none-any.whl\n",
      "Requirement already satisfied: pandas>=0.24 in /usr/local/lib/python3.7/dist-packages (from yfinance) (1.1.5)\n",
      "Requirement already satisfied: numpy>=1.15 in /usr/local/lib/python3.7/dist-packages (from yfinance) (1.19.5)\n",
      "Requirement already satisfied: requests>=2.20 in /usr/local/lib/python3.7/dist-packages (from yfinance) (2.23.0)\n",
      "Requirement already satisfied: multitasking>=0.0.7 in /usr/local/lib/python3.7/dist-packages (from yfinance) (0.0.9)\n",
      "Collecting lxml>=4.5.1\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/30/c0/d0526314971fc661b083ab135747dc68446a3022686da8c16d25fcf6ef07/lxml-4.6.3-cp37-cp37m-manylinux2014_x86_64.whl (6.3MB)\n",
      "\u001b[K     |████████████████████████████████| 6.3MB 34.6MB/s \n",
      "\u001b[?25hCollecting int-date>=0.1.7\n",
      "  Downloading https://files.pythonhosted.org/packages/43/27/31803df15173ab341fe7548c14154b54227dfd8f630daa09a1c6e7db52f7/int_date-0.1.8-py2.py3-none-any.whl\n",
      "Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24->yfinance) (2018.9)\n",
      "Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24->yfinance) (2.8.1)\n",
      "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->yfinance) (2.10)\n",
      "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->yfinance) (1.24.3)\n",
      "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->yfinance) (3.0.4)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.20->yfinance) (2020.12.5)\n",
      "Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.7/dist-packages (from int-date>=0.1.7->stockstats) (1.15.0)\n",
      "Building wheels for collected packages: yfinance\n",
      "  Building wheel for yfinance (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
      "  Created wheel for yfinance: filename=yfinance-0.1.59-py2.py3-none-any.whl size=23442 sha256=1667e194a0dcd1b79c22ea4d7c6c6c1e80ed9bda2f8364aabe722bcc8ace0733\n",
      "  Stored in directory: /root/.cache/pip/wheels/f8/2a/0f/4b5a86e1d52e451757eb6bc17fd899629f0925c777741b6d04\n",
      "Successfully built yfinance\n",
      "Installing collected packages: lxml, yfinance, int-date, stockstats\n",
      "  Found existing installation: lxml 4.2.6\n",
      "    Uninstalling lxml-4.2.6:\n",
      "      Successfully uninstalled lxml-4.2.6\n",
      "Successfully installed int-date-0.1.8 lxml-4.6.3 stockstats-0.3.2 yfinance-0.1.59\n",
      "Collecting wrds\n",
      "  Downloading https://files.pythonhosted.org/packages/d5/2e/ba90330fa84747629ede50303f24220d839019763b8dcba4d182f2afc977/wrds-3.0.10-py3-none-any.whl\n",
      "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from wrds) (1.19.5)\n",
      "Collecting psycopg2-binary\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/6d/45/c519a5cfac05e14b1ccb242138915855293199840598e087b935ba1d86bc/psycopg2_binary-2.8.6-cp37-cp37m-manylinux1_x86_64.whl (3.0MB)\n",
      "\u001b[K     |████████████████████████████████| 3.0MB 32.4MB/s \n",
      "\u001b[?25hRequirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from wrds) (1.1.5)\n",
      "Requirement already satisfied: sqlalchemy in /usr/local/lib/python3.7/dist-packages (from wrds) (1.4.15)\n",
      "Collecting mock\n",
      "  Downloading https://files.pythonhosted.org/packages/5c/03/b7e605db4a57c0f6fba744b11ef3ddf4ddebcada35022927a2b5fc623fdf/mock-4.0.3-py3-none-any.whl\n",
      "Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->wrds) (2.8.1)\n",
      "Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas->wrds) (2018.9)\n",
      "Requirement already satisfied: greenlet!=0.4.17; python_version >= \"3\" in /usr/local/lib/python3.7/dist-packages (from sqlalchemy->wrds) (1.1.0)\n",
      "Requirement already satisfied: importlib-metadata; python_version < \"3.8\" in /usr/local/lib/python3.7/dist-packages (from sqlalchemy->wrds) (4.0.1)\n",
      "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->wrds) (1.15.0)\n",
      "Requirement already satisfied: typing-extensions>=3.6.4; python_version < \"3.8\" in /usr/local/lib/python3.7/dist-packages (from importlib-metadata; python_version < \"3.8\"->sqlalchemy->wrds) (3.7.4.3)\n",
      "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata; python_version < \"3.8\"->sqlalchemy->wrds) (3.4.1)\n",
      "Installing collected packages: psycopg2-binary, mock, wrds\n",
      "Successfully installed mock-4.0.3 psycopg2-binary-2.8.6 wrds-3.0.10\n",
      "Collecting trading_calendars\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/1e/6e/613df8268dea3aac81d3b9d9872d4e48526f8650e970ca1d14911f02dad0/trading_calendars-2.1.1.tar.gz (108kB)\n",
      "\u001b[K     |████████████████████████████████| 112kB 25.2MB/s \n",
      "\u001b[?25hRequirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from trading_calendars) (1.19.5)\n",
      "Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from trading_calendars) (1.1.5)\n",
      "Requirement already satisfied: python-dateutil in /usr/local/lib/python3.7/dist-packages (from trading_calendars) (2.8.1)\n",
      "Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (from trading_calendars) (2018.9)\n",
      "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from trading_calendars) (1.15.0)\n",
      "Requirement already satisfied: toolz in /usr/local/lib/python3.7/dist-packages (from trading_calendars) (0.11.1)\n",
      "Building wheels for collected packages: trading-calendars\n",
      "  Building wheel for trading-calendars (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
      "  Created wheel for trading-calendars: filename=trading_calendars-2.1.1-cp37-none-any.whl size=140919 sha256=1412e4a9f0c4b9bf07716d6a732e773e7b2218cc262e2c2e52777f02bb42a5ff\n",
      "  Stored in directory: /root/.cache/pip/wheels/79/92/44/de8b4d9a7d86cd8f67ea3adfa91bdc7bd441c691b733418cca\n",
      "Successfully built trading-calendars\n",
      "Installing collected packages: trading-calendars\n",
      "Successfully installed trading-calendars-2.1.1\n"
     ]
    }
   ],
   "source": [
    "!pip install git+https://github.com/AI4Finance-Foundation/FinRL-Meta.git\n",
    "!pip install git+https://github.com/AI4Finance-Foundation/ElegantRL.git\n",
    "!pip install yfinance stockstats\n",
    "!pip install wrds\n",
    "!pip install trading_calendars"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "UVdmpnK_3Zcn"
   },
   "source": [
    "# **Part 2: Import Packages**\n",
    "\n",
    "\n",
    "*   **NeoFinRL**\n",
    "*   **ElegantRL**\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "id": "1VM1xKujoz-6"
   },
   "outputs": [],
   "source": [
    "from elegantrl.run import *\n",
    "from meta.wrds.wrds_engineer import WrdsEngineer\n",
    "from meta.wrds.env_stock_wrds import StockTradingEnv\n",
    "from elegantrl.agent import *"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "3n8zcgcn14uq"
   },
   "source": [
    "# **Part 3: Data Fetching and Pre-processing**\n",
    "\n",
    "*   **WrdsEngineer**: An aggregation class of data fetching and pre-processing for WRDS database\n",
    "*   **WrdsEngineer.data_fetch_ohlcv**: Download data by sending sql query to WRDS and preprocessing the raw data to get ohlcv (open, high, low, close, volume) dataframe.\n",
    "*   **WrdsEngineer.data_clean**: Clean the ohlcv data. (Fill up missing rows and missing values.)\n",
    "*   **WrdsEngineer.add_technical_indicators**: Add technical indicators to cleaned ohlcv data.\n",
    "*   **WrdsEngineer.df_to_ary**: Transform the fully preprocessed dataframe into numpy arrary (to put into the environment).\n",
    "\n",
    "\n",
    "\n",
    "> After calling this methods step by step, we will finally get a numpy array to directly put into our environment.\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "E03f6cTeajK4"
   },
   "outputs": [],
   "source": [
    "# Data Fetching\n",
    "#DOW_30_TICKER\n",
    "stock_list = [\"AAPL\",\"MSFT\",\"JPM\",\"V\",\"RTX\",\"PG\",\"GS\",\"NKE\",\"DIS\",\"AXP\",\"HD\",\n",
    "        \"INTC\",\"WMT\",\"IBM\",\"MRK\",\"UNH\",\"KO\",\"CAT\",\"TRV\",\"JNJ\",\"CVX\",\n",
    "        \"MCD\",\"VZ\",\"CSCO\",\"XOM\",\"BA\",\"MMM\",\"PFE\",\"WBA\",\"DD\"]\n",
    "tech_indicator_list = ['macd','boll_ub','boll_lb','rsi_30','dx_30',\n",
    "                       'close_30_sma','close_60_sma']\n",
    "# initialize WrdsEngineer, please fill in your own account info\n",
    "WE = WrdsEngineer() \n",
    "# fetch raw data and calculate ohlcv \n",
    "df = WE.data_fetch_ohlcv(start='2021-01-01',end='2021-01-21',stock_list=stock_list, time_interval=60,\n",
    "                         if_save_tempfile=False)\n",
    "\"\"\"The raw data from WRDS TAQ database is very large. The step above may take hours!!!\n",
    "Here we strongly recommend you save the temp file locally by setting \n",
    "if_save_tempfile=True.\"\"\"\n",
    "# clean the ohlcv data\n",
    "df = WE.data_clean(df)\n",
    "# add technical indicators\n",
    "df = WE.add_technical_indicators(df,tech_indicator_list=tech_indicator_list)\n",
    "print(df.head())\n",
    "# transform dataframe to numpy array\n",
    "ary = WE.df_to_ary(df, tech_indicator_list)\n",
    "\"\"\" You can also save the final array file locally by adding\n",
    "np.save('xxx',ary)\"\"\"\n",
    "print(ary[:10])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "z1j5kLHF2dhJ"
   },
   "source": [
    "# **Part 4: Train, Evaluate and Backtest the Agent by ElegantRL**\n",
    "\n",
    "See https://github.com/AI4Finance-LLC/ElegantRL/blob/master/eRL_demo_StockTrading.ipynb for more demonstrations.\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "KGOPSD6da23k",
    "outputId": "45395b59-d4b2-477d-e75f-43d56ff3b24b"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "| GPU id: 0, cwd: ./AgentPPO/Stock_wrds-v1_0\n",
      "| Remove history\n",
      "ID      Step      MaxR |    avgR      stdR       objA      objC |  avgS  stdS\n",
      "0   7.10e+03      1.05 |\n",
      "0   7.10e+03      1.05 |    1.05      0.00       0.06      0.02 |  1013     0\n",
      "0   1.42e+04      1.05 |    1.02      0.00       0.29      0.01 |  1013     0\n",
      "0   2.13e+04      1.05 |    1.03      0.00       0.14      0.07 |  1013     0\n",
      "0   2.84e+04      1.05 |    1.03      0.00       0.18      0.08 |  1013     0\n",
      "0   3.55e+04      1.05 |    1.02      0.00       0.17      0.06 |  1013     0\n",
      "0   4.26e+04      1.05 |    0.99      0.00       0.12      0.00 |  1013     0\n",
      "0   4.97e+04      1.05 |    0.99      0.00       0.17      0.04 |  1013     0\n",
      "0   5.68e+04      1.05 |    0.99      0.00       0.18      0.01 |  1013     0\n",
      "0   6.39e+04      1.05 |    0.96      0.00       0.16      0.02 |  1013     0\n",
      "0   7.10e+04      1.05 |    0.98      0.00       0.17      0.00 |  1013     0\n",
      "0   7.81e+04      1.05 |    1.00      0.00       0.19      0.08 |  1013     0\n",
      "0   8.52e+04      1.05 |    0.98      0.00       0.18      0.13 |  1013     0\n",
      "0   9.22e+04      1.05 |    1.02      0.00       0.17      0.01 |  1013     0\n",
      "0   9.93e+04      1.05 |    1.02      0.00       0.17      0.10 |  1013     0\n",
      "0   1.06e+05      1.05 |    1.03      0.00       0.17      0.06 |  1013     0\n",
      "0   1.14e+05      1.05 |    1.03      0.00       0.16      0.10 |  1013     0\n",
      "0   1.21e+05      1.05 |    1.03      0.00       0.18      0.02 |  1013     0\n",
      "0   1.28e+05      1.05 |    1.00      0.00       0.18      0.01 |  1013     0\n",
      "0   1.35e+05      1.05 |    0.97      0.00       0.24      0.00 |  1013     0\n",
      "0   1.42e+05      1.05 |    0.96      0.00       0.17      0.00 |  1013     0\n",
      "0   1.49e+05      1.05 |    0.96      0.00       0.18      0.02 |  1013     0\n",
      "0   1.56e+05      1.05 |    0.95      0.00       0.19      0.02 |  1013     0\n",
      "0   1.63e+05      1.05 |    0.96      0.00       0.13      0.23 |  1013     0\n",
      "0   1.70e+05      1.05 |    0.96      0.00       0.12      0.03 |  1013     0\n",
      "0   1.77e+05      1.05 |    0.97      0.00       0.16      0.00 |  1013     0\n",
      "0   1.84e+05      1.05 |    0.96      0.00       0.11      0.01 |  1013     0\n",
      "0   1.92e+05      1.05 |    1.01      0.00       0.14      0.01 |  1013     0\n",
      "0   1.99e+05      1.05 |    1.01      0.00       0.31      0.00 |  1013     0\n",
      "0   2.06e+05      1.05 |    1.01      0.00       0.25      0.00 |  1013     0\n",
      "0   2.13e+05      1.05 |    1.01      0.00       0.23      0.00 |  1013     0\n",
      "0   2.20e+05      1.05 |    1.01      0.00       0.26      0.00 |  1013     0\n",
      "0   2.27e+05      1.05 |    1.01      0.00       0.25      0.00 |  1013     0\n",
      "0   2.34e+05      1.05 |    1.01      0.00       0.24      0.00 |  1013     0\n",
      "0   2.41e+05      1.05 |    1.01      0.00       0.25      0.00 |  1013     0\n",
      "0   2.48e+05      1.05 |    1.01      0.00       0.25      0.00 |  1013     0\n",
      "0   2.55e+05      1.05 |    1.01      0.00       0.19      0.00 |  1013     0\n",
      "0   2.63e+05      1.05 |    1.01      0.00       0.22      0.00 |  1013     0\n",
      "0   2.70e+05      1.05 |    1.01      0.00       0.30      0.00 |  1013     0\n",
      "0   2.77e+05      1.05 |    1.01      0.00       0.26      0.00 |  1013     0\n",
      "0   2.84e+05      1.05 |    1.01      0.00       0.28      0.00 |  1013     0\n",
      "0   2.91e+05      1.05 |    1.00      0.00       0.31      0.00 |  1013     0\n",
      "0   2.98e+05      1.05 |    1.01      0.00       0.12      0.00 |  1013     0\n",
      "0   3.05e+05      1.05 |    1.01      0.00       0.26      0.00 |  1013     0\n",
      "0   3.12e+05      1.05 |    1.01      0.00       0.23      0.00 |  1013     0\n",
      "0   3.19e+05      1.05 |    1.01      0.00       0.24      0.00 |  1013     0\n",
      "0   3.26e+05      1.05 |    1.01      0.00       0.26      0.00 |  1013     0\n",
      "0   3.34e+05      1.05 |    1.01      0.00       0.25      0.00 |  1013     0\n",
      "0   3.41e+05      1.05 |    1.01      0.00       0.30      0.00 |  1013     0\n",
      "0   3.48e+05      1.05 |    1.01      0.00       0.22      0.00 |  1013     0\n",
      "0   3.55e+05      1.05 |    1.02      0.00       0.28      0.00 |  1013     0\n",
      "0   3.62e+05      1.05 |    0.96      0.00       0.27      0.00 |  1013     0\n",
      "0   3.69e+05      1.05 |    0.99      0.00       0.09      0.00 |  1013     0\n",
      "0   3.76e+05      1.05 |    1.04      0.00       0.12      0.00 |  1013     0\n",
      "0   3.83e+05      1.05 |    1.02      0.00       0.16      0.00 |  1013     0\n",
      "0   3.90e+05      1.05 |    0.99      0.00       0.12      0.00 |  1013     0\n",
      "0   3.97e+05      1.05 |    1.01      0.00       0.22      0.00 |  1013     0\n",
      "0   4.04e+05      1.05 |    1.01      0.00       0.17      0.06 |  1013     0\n",
      "0   4.12e+05      1.05 |    1.02      0.00       0.17      0.01 |  1013     0\n",
      "0   4.19e+05      1.05 |    1.01      0.00       0.08      0.00 |  1013     0\n",
      "0   4.26e+05      1.05 |    1.01      0.00       0.14      0.00 |  1013     0\n",
      "0   4.33e+05      1.05 |    1.01      0.00       0.18      0.03 |  1013     0\n",
      "0   4.40e+05      1.05 |    1.01      0.00       0.17      0.02 |  1013     0\n",
      "0   4.47e+05      1.05 |    1.01      0.00       0.28      0.00 |  1013     0\n",
      "0   4.54e+05      1.05 |    1.01      0.00       0.15      0.00 |  1013     0\n",
      "0   4.61e+05      1.05 |    1.01      0.00       0.16      0.01 |  1013     0\n",
      "0   4.68e+05      1.05 |    1.03      0.00       0.15      0.00 |  1013     0\n",
      "0   4.75e+05      1.05 |    1.04      0.00       0.14      0.00 |  1013     0\n",
      "0   4.83e+05      1.05 |    1.04      0.00       0.17      0.01 |  1013     0\n",
      "0   4.90e+05      1.05 |    1.01      0.00       0.12      0.00 |  1013     0\n",
      "0   4.97e+05      1.05 |    1.02      0.00       0.13      0.00 |  1013     0\n",
      "0   5.04e+05      1.05 |    1.01      0.00       0.13      0.00 |  1013     0\n",
      "| SavedDir: ./AgentPPO/Stock_wrds-v1_0\n",
      "| UsedTime: 3372\n",
      "| GPU id: 0, cwd: ./AgentPPO/Stock_wrds-v1_0\n",
      "Loaded act: ./AgentPPO/Stock_wrds-v1_0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[0.9999582054744706,\n",
       " 0.9998697794989394,\n",
       " 0.9997815491954077,\n",
       " 0.9816760269226112,\n",
       " 0.9982174832436048,\n",
       " 0.9981505949133206,\n",
       " 0.998174767387467,\n",
       " 0.9981842929703372,\n",
       " 0.9980826186677039,\n",
       " 0.9979927946130125,\n",
       " 0.9980128004818435,\n",
       " 0.9979491235523446,\n",
       " 0.997950057158042,\n",
       " 0.9978688023066237,\n",
       " 0.9977688871527819,\n",
       " 0.997590915056724,\n",
       " 0.9974798884851261,\n",
       " 0.9975092001425028,\n",
       " 1.011799042672329,\n",
       " 1.011953915858813,\n",
       " 1.0118615847661676,\n",
       " 1.011937285564322,\n",
       " 1.012026657913432,\n",
       " 1.0119525798539435,\n",
       " 1.0120772514841745,\n",
       " 1.0120132210681565,\n",
       " 1.0120299535612742,\n",
       " 1.0120364510019477,\n",
       " 1.0120831375344743,\n",
       " 1.0122126139018024,\n",
       " 1.0118935848865223,\n",
       " 0.9768551145898311,\n",
       " 1.012146363717738,\n",
       " 1.0119252227692679,\n",
       " 1.0120144841971745,\n",
       " 1.0124282485872362,\n",
       " 1.0127693551633326,\n",
       " 1.013769409468197,\n",
       " 1.0130878444548004,\n",
       " 1.013345625243525,\n",
       " 1.0131046358878522,\n",
       " 1.0131217342303012,\n",
       " 1.013056572973549,\n",
       " 0.9780211547240754,\n",
       " 1.0130633081924731,\n",
       " 1.0133263761645244,\n",
       " 1.0133167728189947,\n",
       " 1.0133097527695436,\n",
       " 1.0134922129373207,\n",
       " 1.0133154403733977,\n",
       " 1.0136415148046487,\n",
       " 1.0137054330378985,\n",
       " 1.0136453125220006,\n",
       " 1.0139490746512405,\n",
       " 1.0138276494790361,\n",
       " 1.013607802845516,\n",
       " 0.9860041886406408,\n",
       " 1.0139804041214227,\n",
       " 1.0138820680766287,\n",
       " 1.0138480915817947,\n",
       " 1.0140082417810792,\n",
       " 1.014188429275594,\n",
       " 1.0141006456431692,\n",
       " 0.9864448148795071,\n",
       " 1.014215826877474,\n",
       " 1.014280833075157,\n",
       " 1.0138905358657475,\n",
       " 1.0134917810807789,\n",
       " 1.0138575764606255,\n",
       " 1.0136038968422925,\n",
       " 1.0134830391208345,\n",
       " 1.0134096322205763,\n",
       " 1.0134593754703602,\n",
       " 1.013508561448177,\n",
       " 1.0136959405304602,\n",
       " 1.0136744561717157,\n",
       " 0.9849377182263801,\n",
       " 1.0146620223503002,\n",
       " 1.01504586140446,\n",
       " 1.014994250392607,\n",
       " 1.0147044665705918,\n",
       " 1.014644495491936,\n",
       " 1.0145907904874647,\n",
       " 1.014671124129126,\n",
       " 1.0147581090891247,\n",
       " 1.0146143996938546,\n",
       " 1.0147210548660657,\n",
       " 1.015027998290543,\n",
       " 1.0153992238680019,\n",
       " 1.015130930710811,\n",
       " 1.015310088104014,\n",
       " 1.0153745265712548,\n",
       " 1.015201173215473,\n",
       " 1.0152289912282044,\n",
       " 1.015061431468106,\n",
       " 1.014990186820389,\n",
       " 1.0151297275827764,\n",
       " 1.0153694384341185,\n",
       " 1.015370405529212,\n",
       " 1.0155926543079987,\n",
       " 1.0156699714608555,\n",
       " 1.016122131317706,\n",
       " 1.016282883706358,\n",
       " 1.0160312308815793,\n",
       " 1.0163991205308618,\n",
       " 1.016085669982206,\n",
       " 1.0164140722879798,\n",
       " 1.0165661511985211,\n",
       " 1.0166892328444272,\n",
       " 1.0165788108407345,\n",
       " 1.016457966735079,\n",
       " 1.016406926952628,\n",
       " 1.0162711231252972,\n",
       " 1.0159237224804754,\n",
       " 1.0158257793637226,\n",
       " 1.0161401560622139,\n",
       " 1.0161957379317523,\n",
       " 1.0158379163323759,\n",
       " 1.015755896068265,\n",
       " 1.0160237607698632,\n",
       " 1.016231990469349,\n",
       " 1.0161896324089799,\n",
       " 1.0164417430278834,\n",
       " 1.0162058598776615,\n",
       " 1.0160199515508828,\n",
       " 1.01650564368328,\n",
       " 1.0167738004389781,\n",
       " 1.016485018227949,\n",
       " 1.0163711627178713,\n",
       " 1.0163356583469714,\n",
       " 1.0162129220768592,\n",
       " 1.016084779556501,\n",
       " 1.01615074354583,\n",
       " 0.9942434299184834,\n",
       " 1.0160586810706198,\n",
       " 1.0159773416259275,\n",
       " 1.0157617002299935,\n",
       " 1.0158087750140936,\n",
       " 1.0159090800609942,\n",
       " 1.0158084202668303,\n",
       " 0.9992530089625825,\n",
       " 1.0130315150704565,\n",
       " 1.0130673822158907,\n",
       " 1.013194049801277,\n",
       " 1.0135309140421735,\n",
       " 0.9997029509320126,\n",
       " 0.9996951778895073,\n",
       " 1.013415390369954,\n",
       " 1.0129872557498991,\n",
       " 1.0130427792589256,\n",
       " 1.0132167750557792,\n",
       " 1.0130448215176266,\n",
       " 1.0129084650798277,\n",
       " 1.0131416776383335,\n",
       " 1.0001276110123898,\n",
       " 1.012935608548634,\n",
       " 1.0123797553931864,\n",
       " 1.0121927195651588,\n",
       " 1.0123658975561591,\n",
       " 1.0123711433651017,\n",
       " 1.0122632753486376,\n",
       " 1.0126062949998138,\n",
       " 0.9995754386865384,\n",
       " 1.0129548321551582,\n",
       " 1.0127468842921028,\n",
       " 1.0128007237966374,\n",
       " 1.012574712036901,\n",
       " 1.0127925892020262,\n",
       " 1.0130038931593883,\n",
       " 1.0131185586589622,\n",
       " 1.0130869828318518,\n",
       " 1.0131684965624475,\n",
       " 0.9996805933736082,\n",
       " 1.0133017031739004,\n",
       " 1.0133081702916846,\n",
       " 0.9994161005467053,\n",
       " 1.0123203022374783,\n",
       " 1.0123963852907427,\n",
       " 1.0123731041627027,\n",
       " 1.0126784895425274,\n",
       " 1.01225071275964,\n",
       " 1.0123262411276408,\n",
       " 1.0122922308191777,\n",
       " 1.0121116188256019,\n",
       " 1.0121018381697262,\n",
       " 1.0124161955636515,\n",
       " 1.0121300088474956,\n",
       " 1.0121088128164546,\n",
       " 1.0118513901054011,\n",
       " 1.0121310775301888,\n",
       " 1.0116827584518224,\n",
       " 1.0116033342710924,\n",
       " 1.011709941234707,\n",
       " 1.011464451077273,\n",
       " 1.0113548422799088,\n",
       " 1.0111934972689716,\n",
       " 1.01117573540549,\n",
       " 1.0112612811542532,\n",
       " 1.0112839186909344,\n",
       " 1.0113594682547282,\n",
       " 1.0114345424679,\n",
       " 1.011332690928841,\n",
       " 1.008883529506018,\n",
       " 1.0112645499801005,\n",
       " 1.0112183343300833,\n",
       " 1.0111073258677636,\n",
       " 1.0111640528450427,\n",
       " 1.0113858119327492,\n",
       " 1.0112907128891233,\n",
       " 1.0110513780124608,\n",
       " 1.0109906143112861,\n",
       " 1.0110158479537308,\n",
       " 1.011160048476915,\n",
       " 1.0112798021160547,\n",
       " 1.0189433612863084,\n",
       " 1.0115108015514813,\n",
       " 1.0117271674153654,\n",
       " 1.0117521817014823,\n",
       " 1.0118391039839294,\n",
       " 1.0118644277602642,\n",
       " 1.0117100637147547,\n",
       " 1.011548968925115,\n",
       " 1.011425809949381,\n",
       " 1.0115389437302529,\n",
       " 1.0114964879175286,\n",
       " 1.0114963214155386,\n",
       " 1.0120730703164462,\n",
       " 1.0122585980791114,\n",
       " 1.0122769556101996,\n",
       " 1.0122067602244618,\n",
       " 1.0119884047871837,\n",
       " 1.011691947228738,\n",
       " 1.011756226387437,\n",
       " 1.0169249157946578,\n",
       " 1.0166798616104147,\n",
       " 1.0174341842931882,\n",
       " 1.0188530476308575,\n",
       " 1.018478943662012,\n",
       " 1.0196752895447998,\n",
       " 1.018757388079322,\n",
       " 1.0199629178095706,\n",
       " 1.0197940649158133,\n",
       " 1.018897026975652,\n",
       " 1.0180561587998622,\n",
       " 1.0183014761757527,\n",
       " 1.0186957885043926,\n",
       " 1.0191526139771103,\n",
       " 1.0195657962909777,\n",
       " 1.0195831999466813,\n",
       " 1.0194409962456674,\n",
       " 1.0194650012765856,\n",
       " 1.019591077400609,\n",
       " 1.0195486948415275,\n",
       " 1.0200238141727913,\n",
       " 1.0184285157486879,\n",
       " 1.0178965702833147,\n",
       " 1.0174079867894823,\n",
       " 1.0173754357058769,\n",
       " 1.0180814250099677,\n",
       " 1.0183315410939504,\n",
       " 1.0189483741930252,\n",
       " 1.0193438285150618,\n",
       " 1.0196413310630688,\n",
       " 1.0198319851121318,\n",
       " 1.020021313902086,\n",
       " 1.0209548755407931,\n",
       " 1.0205648098530633,\n",
       " 1.021554257084834,\n",
       " 1.0219662901147017,\n",
       " 1.0221282512288405,\n",
       " 1.0232321894700913,\n",
       " 1.0224881335466496,\n",
       " 1.0218739821337255,\n",
       " 1.0217429657619042,\n",
       " 1.0217148352177983,\n",
       " 1.0217488036756857,\n",
       " 1.0215382424146198,\n",
       " 1.0215232477416187,\n",
       " 1.021242050832707,\n",
       " 1.022401436405633,\n",
       " 1.022640300094301,\n",
       " 1.0226955287385202,\n",
       " 1.021707337057406,\n",
       " 1.021790102831369,\n",
       " 1.0219352759425324,\n",
       " 1.0223951318210784,\n",
       " 1.021915177419454,\n",
       " 1.021530421196401,\n",
       " 1.02126425663135,\n",
       " 1.020749592288459,\n",
       " 1.020081438022358,\n",
       " 1.0200092650171884,\n",
       " 1.0201505872810028,\n",
       " 1.0201943472622672,\n",
       " 1.020389248646532,\n",
       " 1.0209931846211822,\n",
       " 1.021034306080481,\n",
       " 1.0212078250015404,\n",
       " 1.0211849435278424,\n",
       " 1.0205591924067032,\n",
       " 1.0204929798421696,\n",
       " 1.0207860851463004,\n",
       " 1.020853496079992,\n",
       " 1.0211699612259453,\n",
       " 1.0210267864053186,\n",
       " 1.0207988513295518,\n",
       " 1.020871333133831,\n",
       " 1.0207968367232152,\n",
       " 1.020803639539807,\n",
       " 1.0210000553425214,\n",
       " 1.0206375013051587,\n",
       " 1.0201501429837825,\n",
       " 1.0202914566060908,\n",
       " 1.0205257024069665,\n",
       " 1.020176121644012,\n",
       " 1.020518746513943,\n",
       " 1.0207070356946324,\n",
       " 1.0207657338246954,\n",
       " 1.020574375393277,\n",
       " 1.0202219477093109,\n",
       " 1.019799244998471,\n",
       " 1.0204493029329924,\n",
       " 1.0204807072412014,\n",
       " 1.0199747416766387,\n",
       " 1.0195509938709075,\n",
       " 1.0193839767300445,\n",
       " 1.0195944495779174,\n",
       " 1.0197631537903624,\n",
       " 1.0191518399335113,\n",
       " 1.0191360327204615,\n",
       " 1.0185684922758693,\n",
       " 1.0182792125066311,\n",
       " 1.0178327648241512,\n",
       " 1.0182156028725977,\n",
       " 1.0184230036997333,\n",
       " 1.0185892011374316,\n",
       " 1.0188366765850116,\n",
       " 1.0191992362944233,\n",
       " 1.0194030669241168,\n",
       " 1.0193627892601338,\n",
       " 1.019196689460573,\n",
       " 1.0197147859510487,\n",
       " 1.0197170983235126,\n",
       " 1.0195012970284067,\n",
       " 1.0196904417356618,\n",
       " 1.0192817403188592,\n",
       " 1.0189939869991995,\n",
       " 1.0187716935786613,\n",
       " 1.0183655280414237,\n",
       " 1.018226001034385,\n",
       " 1.0184170720979486,\n",
       " 1.0184017405688957,\n",
       " 1.0184549520029562,\n",
       " 1.0184201136923943,\n",
       " 1.018304088900745,\n",
       " 1.0189359162120977,\n",
       " 1.0191826369904302,\n",
       " 1.0195294731387519,\n",
       " 1.0190844973942632,\n",
       " 1.0194837127774175,\n",
       " 1.0198822288472416,\n",
       " 1.0199845008002932,\n",
       " 1.019853933894556,\n",
       " 1.019884389032276,\n",
       " 1.019805487830758,\n",
       " 1.020077108539938,\n",
       " 1.0203278614372495,\n",
       " 1.020404924589929,\n",
       " 1.0204376746933468,\n",
       " 1.020186591413004,\n",
       " 1.0200141005095629,\n",
       " 1.0197140817167234,\n",
       " 1.0195951387473992,\n",
       " 1.0196939929788207,\n",
       " 1.0198701159898287,\n",
       " 1.0200154431703528,\n",
       " 1.020031274242437,\n",
       " 1.0194438783164355,\n",
       " 1.019374530055699,\n",
       " 1.0197827787627547,\n",
       " 1.0197650346919012,\n",
       " 1.0193882768599647,\n",
       " 1.0195190097093307,\n",
       " 1.0203048772698013,\n",
       " 1.0203727594217056,\n",
       " 1.0205572299630814,\n",
       " 1.0210072710493667,\n",
       " 1.0204068754677995,\n",
       " 1.0202663457170942,\n",
       " 1.020494761720595,\n",
       " 1.0202889855192154,\n",
       " 1.0205245444293651,\n",
       " 1.0203203340316478,\n",
       " 1.020185411229063,\n",
       " 1.0203618530023613,\n",
       " 1.0200699626030718,\n",
       " 1.0199903448287613,\n",
       " 1.0199487108185592,\n",
       " 1.0198562353272576,\n",
       " 1.0199860126351799,\n",
       " 1.0197548020377134,\n",
       " 1.0200756087171121,\n",
       " 1.0201227892257674,\n",
       " 1.0198563723884775,\n",
       " 1.0200280576129557,\n",
       " 1.019987578227824,\n",
       " 1.0201327100807018,\n",
       " 1.0200142589441608,\n",
       " 1.0199915339608703,\n",
       " 1.0201965443370453,\n",
       " 1.0201669976604797,\n",
       " 1.020161681985036,\n",
       " 1.020212938146797,\n",
       " 1.0203161168852302,\n",
       " 1.0205441091948841,\n",
       " 1.0205932399029596,\n",
       " 1.0207533999360174,\n",
       " 1.0205142908659819,\n",
       " 1.0204654184426427,\n",
       " 1.0202551947771692,\n",
       " 1.0201609894521144,\n",
       " 1.020208463131509,\n",
       " 1.0205578163136482,\n",
       " 1.0205907375153662,\n",
       " 1.0205049984109686,\n",
       " 1.0210708463601665,\n",
       " 1.0208554906117686,\n",
       " 1.0210106263072614,\n",
       " 1.0211054084776048,\n",
       " 1.0209873253103499,\n",
       " 1.0212225573284348,\n",
       " 1.0213033865014431,\n",
       " 1.0209931551246454,\n",
       " 1.0211284201207391,\n",
       " 1.0211054049643444,\n",
       " 1.0213484691874126,\n",
       " 1.0214494036671875,\n",
       " 1.0213729529234294,\n",
       " 1.0215398579368415,\n",
       " 1.0217446146588995,\n",
       " 1.0213587260168402,\n",
       " 1.0212237445793952,\n",
       " 1.0213574079190313,\n",
       " 1.021544982768305,\n",
       " 1.0214836216885503,\n",
       " 1.0216459571740484,\n",
       " 1.0216532049705298,\n",
       " 1.0216126530361467,\n",
       " 1.0215585198925268,\n",
       " 1.0218306523285312,\n",
       " 1.0217692499911717,\n",
       " 1.0215796753212039,\n",
       " 1.0215893239253788,\n",
       " 1.0215046189879367,\n",
       " 1.021343370685416,\n",
       " 1.0212251477082586,\n",
       " 1.0211240006941136,\n",
       " 1.0211134917673272,\n",
       " 1.0213707541039596,\n",
       " 1.0213924041328901,\n",
       " 1.0215320845812494,\n",
       " 1.021684306867717,\n",
       " 1.0217063106497637,\n",
       " 1.0219713530488235,\n",
       " 1.022102824420877,\n",
       " 1.021480855076661,\n",
       " 1.0212068553932703,\n",
       " 1.0212562790689146,\n",
       " 1.021653978254119,\n",
       " 1.022303640878591,\n",
       " 1.0225215674183028,\n",
       " 1.0221585571721448,\n",
       " 1.0221782096581191,\n",
       " 1.0223756077437145,\n",
       " 1.0222668478790295,\n",
       " 1.022463013638295,\n",
       " 1.022510974202391,\n",
       " 1.0225511020619635,\n",
       " 1.0225185147862832,\n",
       " 1.0357358577696638,\n",
       " 1.0357302805716626,\n",
       " 1.0358049451512277,\n",
       " 1.0354885575570163,\n",
       " 1.0355977136159251,\n",
       " 1.0352716190300202,\n",
       " 1.0351918263968587,\n",
       " 1.031243715006131,\n",
       " 1.032612025295991,\n",
       " 1.032473431398374,\n",
       " 1.0324199680243262,\n",
       " 1.0322971556866187,\n",
       " 1.032035314435822,\n",
       " 1.0319966679041572,\n",
       " 1.0323684910949011,\n",
       " 1.0325170127205665,\n",
       " 1.0322504571312598,\n",
       " 1.0321770596774558,\n",
       " 1.0320861580938316,\n",
       " 1.0319771845065329,\n",
       " 1.0320321364189455,\n",
       " 1.031911632069716,\n",
       " 1.0318430704710007,\n",
       " 1.0316988183791032,\n",
       " 1.0318258627249435,\n",
       " 1.0315021003207931,\n",
       " 1.031502701390654,\n",
       " 1.0316609134991988,\n",
       " 1.031453652284581,\n",
       " 1.0313362476981551,\n",
       " 1.0315429150392272,\n",
       " 1.0315786816571229,\n",
       " 1.0315469463716416,\n",
       " 1.03165330735202,\n",
       " 1.0309073945993523,\n",
       " 1.0304088096632549,\n",
       " 1.0540172099011667,\n",
       " 1.0539749214172072,\n",
       " 1.0539447845436247,\n",
       " 1.0543641169197826,\n",
       " 1.05446356848301,\n",
       " 1.0544355041528042,\n",
       " 1.0542665160056146,\n",
       " 1.0542615080712163,\n",
       " 1.0540718417863617,\n",
       " 1.0539472980255942,\n",
       " 1.0538315358148462,\n",
       " 1.054037005781634,\n",
       " 1.0540525651124453,\n",
       " 1.0541440692129374,\n",
       " 1.054101975107412,\n",
       " 1.0541513041226616,\n",
       " 1.0540989634946358,\n",
       " 1.0542098287393682,\n",
       " 1.0541972213473465,\n",
       " 1.0544849360075415,\n",
       " 1.0546179671790452,\n",
       " 1.0545345909076578,\n",
       " 1.0545442769829145,\n",
       " 1.054755995065734,\n",
       " 1.0550789744222628,\n",
       " 1.0552749907943375,\n",
       " 1.0550159896859208,\n",
       " 1.0549247890908777,\n",
       " 1.0548132738035487,\n",
       " 1.0546920199139942,\n",
       " 1.0403210935471117,\n",
       " 1.0526827189659722,\n",
       " 1.0525424376194377,\n",
       " 1.0526205272970486,\n",
       " 1.0524911295161947,\n",
       " 1.0524165851090261,\n",
       " 1.0523600455261106,\n",
       " 1.052512048727654,\n",
       " 1.052488461456698,\n",
       " 1.052290340478928,\n",
       " 1.0524485873751988,\n",
       " 1.0524119938804049,\n",
       " 1.052373839514442,\n",
       " 1.0524143125864966,\n",
       " 1.052245404936758,\n",
       " 1.0521524390238353,\n",
       " 1.051753833117958,\n",
       " 1.051579218537515,\n",
       " 1.0515710773816696,\n",
       " 1.0514982481934112,\n",
       " 1.0515370117361833,\n",
       " 1.0517964271991347,\n",
       " 1.0518178107719283,\n",
       " 1.0521095739026358,\n",
       " 1.0521303352869624,\n",
       " 1.0521759128493817,\n",
       " 1.0520262942049614,\n",
       " 1.0519208332921977,\n",
       " 1.0517418637445484,\n",
       " 1.0513887139407825,\n",
       " 1.051344771095195,\n",
       " 1.0514878615134275,\n",
       " 1.0516408306337435,\n",
       " 1.051815880717469,\n",
       " 1.051869019607994,\n",
       " 1.0518484785413003,\n",
       " 1.0518670116655318,\n",
       " 1.0519553578588308,\n",
       " 1.0519514295180874,\n",
       " 1.0517800403829274,\n",
       " 1.0522279258959157,\n",
       " 1.0520768322726404,\n",
       " 1.0517991146249592,\n",
       " 1.0522180665994958,\n",
       " 1.0522090799136083,\n",
       " 1.0525570733487823,\n",
       " 1.0527576029403714,\n",
       " 1.052752552634381,\n",
       " 1.0528653829856747,\n",
       " 1.0529430768983048,\n",
       " 1.0529250728145747,\n",
       " 1.0529578048963848,\n",
       " 1.0530479500501284,\n",
       " 1.0525760652212064,\n",
       " 1.0527403023262454,\n",
       " 1.0528872465302506,\n",
       " 1.0525705294372103,\n",
       " 1.0525084128034519,\n",
       " 1.052483776801514,\n",
       " 1.0527874891656532,\n",
       " 1.0531974555687225,\n",
       " 1.053820908146365,\n",
       " 1.0534814595666273,\n",
       " 1.0535927836538204,\n",
       " 1.0537675038761223,\n",
       " 1.0537493725900633,\n",
       " 1.053662738634013,\n",
       " 1.053270773353027,\n",
       " 1.0530951446226744,\n",
       " 1.0529993513531553,\n",
       " 1.0529995853424905,\n",
       " 1.052975305263491,\n",
       " 1.0530002949569441,\n",
       " 1.0530209395652999,\n",
       " 1.0531061274208924,\n",
       " 1.0530374799955997,\n",
       " 1.0528406977552796,\n",
       " 1.0517033655155092,\n",
       " 1.0510433941659243,\n",
       " 1.051887612683783,\n",
       " 1.050414240244174,\n",
       " 1.0515344339867219,\n",
       " 1.0519924922882908,\n",
       " 1.0517413980325596,\n",
       " 1.050594124405411,\n",
       " 1.0487244102530306,\n",
       " 1.0491388482717579,\n",
       " 1.0478924729194616,\n",
       " 1.0484129144311716,\n",
       " 1.048330241704443,\n",
       " 1.0471169685361623,\n",
       " 1.0478646594480583,\n",
       " 1.048633121056173,\n",
       " 1.047695640004464,\n",
       " 1.0479481412459801,\n",
       " 1.0473955058748619,\n",
       " 1.0474685673767847,\n",
       " 1.0470896207518874,\n",
       " 1.0476740688558914,\n",
       " 1.0475775788743482,\n",
       " 1.0465209602369276,\n",
       " 1.0464907139859216,\n",
       " 1.0475201491613069,\n",
       " 1.0467718753765534,\n",
       " 1.0466963071439548,\n",
       " 1.0475991695731113,\n",
       " 1.0472520930385776,\n",
       " 1.048026390674222,\n",
       " 1.047558096024527,\n",
       " 1.0477968539500306,\n",
       " 1.0481026313180724,\n",
       " 1.0483978634885924,\n",
       " 1.048049418317877,\n",
       " 1.0474153421992023,\n",
       " 1.0462546288483003,\n",
       " 1.0463744646317812,\n",
       " 1.0472798380545258,\n",
       " 1.0467626325257582,\n",
       " 1.047291670164361,\n",
       " 1.046961821983825,\n",
       " 1.047537733374926,\n",
       " 1.0480712636551204,\n",
       " 1.048418032343432,\n",
       " 1.0494175439506954,\n",
       " 1.049710546706848,\n",
       " 1.048923369823812,\n",
       " 1.0495915510267804,\n",
       " 1.0491572556200703,\n",
       " 1.048659369448611,\n",
       " 1.0485421300948452,\n",
       " 1.0486155961963863,\n",
       " 1.0487685764915644,\n",
       " 1.048454128842123,\n",
       " 1.048768546213997,\n",
       " 1.0486488007509602,\n",
       " 1.0490646655662557,\n",
       " 1.0495268260678554,\n",
       " 1.0495627109158046,\n",
       " 1.049547274730447,\n",
       " 1.0494479843899438,\n",
       " 1.049697045706185,\n",
       " 1.0496024712363998,\n",
       " 1.0494371063389207,\n",
       " 1.0492732555899276,\n",
       " 1.0488212741138714,\n",
       " 1.0492133856667767,\n",
       " 1.0496391748921734,\n",
       " 1.0492556725157878,\n",
       " 1.049417806213786,\n",
       " 1.04895702878101,\n",
       " 1.0490809878748149,\n",
       " 1.0491926571011294,\n",
       " 1.0483529193895706,\n",
       " 1.0483012920421415,\n",
       " 1.0487689061779304,\n",
       " 1.048996696090975,\n",
       " 1.0492216234304965,\n",
       " 1.0487317844693802,\n",
       " 1.0486298681094341,\n",
       " 1.0480743584845231,\n",
       " 1.0479592241706253,\n",
       " 1.0477528225532486,\n",
       " 1.047678653328462,\n",
       " 1.047408594016005,\n",
       " 1.0478042693194292,\n",
       " 1.0477614535505508,\n",
       " 1.04740322038918,\n",
       " 1.0473071661310014,\n",
       " 1.047304501741176,\n",
       " 1.047549174867459,\n",
       " 1.0479516240015974,\n",
       " 1.0478520022559492,\n",
       " 1.0480363528706282,\n",
       " 1.0477529777826278,\n",
       " 1.0474041143542128,\n",
       " 1.0474042409216686,\n",
       " 1.047262726135499,\n",
       " 1.047764605347462,\n",
       " 1.047238930856056,\n",
       " 1.0471835000482674,\n",
       " 1.0473499225649792,\n",
       " 1.0474728308319163,\n",
       " 1.047034980634132,\n",
       " 1.0466550731337534,\n",
       " 1.0465874372342416,\n",
       " 1.0465546392433056,\n",
       " 1.0466455141939341,\n",
       " 1.0465818713093884,\n",
       " 1.0466179030981393,\n",
       " 1.0469341503674694,\n",
       " 1.0471886643274304,\n",
       " 1.0474849196980847,\n",
       " 1.0473481855703868,\n",
       " 1.0471461636406991,\n",
       " 1.0474544400541452,\n",
       " 1.0471896288495373,\n",
       " 1.0471514956309154,\n",
       " 1.046530790044691,\n",
       " 1.0461859059925303,\n",
       " 1.0456824080286815,\n",
       " 1.0454039846994865,\n",
       " 1.0453371238703828,\n",
       " 1.0454191752527058,\n",
       " 1.0453751951309436,\n",
       " 1.0451705642319506,\n",
       " 1.0454361455451924,\n",
       " 1.0456281621035692,\n",
       " 1.0456335774369954,\n",
       " 1.0453778362533206,\n",
       " 1.0449926328622272,\n",
       " 1.0447175118912055,\n",
       " 1.0447611817003701,\n",
       " 1.04519587169495,\n",
       " 1.0450423315845678,\n",
       " 1.045046275963607,\n",
       " 1.0448609160576987,\n",
       " 1.0446451836686195,\n",
       " 1.0449215623319252,\n",
       " 1.0450458576462318,\n",
       " 1.044907851839237,\n",
       " 1.0449316040276604,\n",
       " 1.0446738642992028,\n",
       " 1.0445688392911598,\n",
       " 1.044405494329757,\n",
       " 1.0446703716328438,\n",
       " 1.044461380763874,\n",
       " 1.04439875649643,\n",
       " 1.0446644189062884,\n",
       " 1.044623923589042,\n",
       " 1.0446792410579566,\n",
       " 1.0442677032790137,\n",
       " 1.0441248195450112,\n",
       " 1.043943643529003,\n",
       " 1.0438782365659345,\n",
       " 1.0438560009309927,\n",
       " 1.043631203240837,\n",
       " 1.043977643043439,\n",
       " 1.0439900777424842,\n",
       " 1.0441347414452014,\n",
       " 1.043897305252389,\n",
       " 1.044068337532888,\n",
       " 1.0439598857434045,\n",
       " 1.0443785689504173,\n",
       " 1.0438905332005946,\n",
       " 1.0436693799110925,\n",
       " 1.0433318178460973,\n",
       " 1.0431773047264379,\n",
       " 1.0431844165916906,\n",
       " 1.0431052358395054,\n",
       " 1.0436131422473545,\n",
       " 1.0435452032136388,\n",
       " 1.0438256866695288,\n",
       " 1.0442073669607153,\n",
       " 1.0443538660226963,\n",
       " 1.0443173519289037,\n",
       " 1.044010528145658,\n",
       " 1.0438980835266698,\n",
       " 1.0436989983234959,\n",
       " 1.043557984089725,\n",
       " 1.043487911376163,\n",
       " 1.04332815086807,\n",
       " 1.043352172604276,\n",
       " 1.0434345405136267,\n",
       " 1.0432545182293982,\n",
       " 1.0433141857755472,\n",
       " 1.0432043241602058,\n",
       " 1.043413647782212,\n",
       " 1.0433612091090312,\n",
       " 1.0434463592745218,\n",
       " 1.0436388356624398,\n",
       " 1.0436093421575294,\n",
       " 1.043360564170591,\n",
       " 1.0435990293229713,\n",
       " 1.0435336390442727,\n",
       " 1.0437376911126532,\n",
       " 1.0439623422644388,\n",
       " 1.0439616788283426,\n",
       " 1.0441240364272928,\n",
       " 1.0439314969629616,\n",
       " 1.0439605369760903,\n",
       " 1.0437260589738138,\n",
       " 1.0438063562263162,\n",
       " 1.043902113799302,\n",
       " 1.0438411524816265,\n",
       " 1.0436016649174291,\n",
       " 1.0435859140869423,\n",
       " 1.0439505457715614,\n",
       " 1.0442375752371376,\n",
       " 1.0444629048432474,\n",
       " 1.044177112630732,\n",
       " 1.043926137897117,\n",
       " 1.0438074677980325,\n",
       " 1.043825797211387,\n",
       " 1.0440141860825418,\n",
       " 1.0440461923895,\n",
       " 1.044147353365934,\n",
       " 1.0443817461399818,\n",
       " 1.0446362543293923,\n",
       " 1.0444643699088723,\n",
       " 1.0445207328686432,\n",
       " 1.044450819028067,\n",
       " 1.0445676584490327,\n",
       " 1.0443687364415497,\n",
       " 1.0444112998935822,\n",
       " 1.044586608763327,\n",
       " 1.044293081944986,\n",
       " 1.0442299979543612,\n",
       " 1.0443103851059357,\n",
       " 1.044255308963901,\n",
       " 1.0442855130096527,\n",
       " 1.0444855697730988,\n",
       " 1.0444546967376984,\n",
       " 1.0444654873331574,\n",
       " 1.0447016316610964,\n",
       " 1.0444868139324923,\n",
       " 1.0444035413931276,\n",
       " 1.0442304025388336,\n",
       " 1.044190069857065,\n",
       " 1.0439879931538727,\n",
       " 1.0440091266300264,\n",
       " 1.0440742382793429,\n",
       " 1.0443447117416902,\n",
       " 1.0442129257603974,\n",
       " 1.0444429583530943,\n",
       " 1.044054889194278,\n",
       " 1.043935927775212,\n",
       " 1.0441713453892623,\n",
       " 1.0441764184045974,\n",
       " 1.0444846399019052,\n",
       " 1.044550066381582,\n",
       " 1.04471377989154,\n",
       " 1.0444992618796924,\n",
       " 1.044352381301488,\n",
       " 1.0439393245714954,\n",
       " 1.0439452493624135,\n",
       " 1.0436467874576343,\n",
       " 1.0438851505285511,\n",
       " 1.0442168830818717,\n",
       " 1.0444508808324635,\n",
       " 1.0447894248342275,\n",
       " 1.0448696999825429,\n",
       " 1.0447006083325672,\n",
       " 1.0442521411721364,\n",
       " 1.0446116700865438,\n",
       " 1.044596018482471,\n",
       " 1.0445307492839933,\n",
       " 1.0445192418896625,\n",
       " 1.0447877993261554,\n",
       " 1.0450502951015852,\n",
       " 1.0448634029001864,\n",
       " 1.0452610678309184,\n",
       " 1.0451954564728352,\n",
       " 1.0451968142393508,\n",
       " 1.0453479778585295,\n",
       " 1.0456925342215764,\n",
       " 1.0458502282126876,\n",
       " 1.0458516065788295,\n",
       " 1.0458463477866022,\n",
       " 1.045786650464281,\n",
       " 1.0459449653984638,\n",
       " 1.0461385097039373,\n",
       " 1.0457866139297565,\n",
       " 1.0456604760359374,\n",
       " 1.0458288935600877,\n",
       " 1.0456128128689086,\n",
       " 1.0458392011600743,\n",
       " 1.0456200851978805,\n",
       " 1.0456206733231546,\n",
       " 1.045922008436744,\n",
       " 1.0460008356743995,\n",
       " 1.0461872902535483,\n",
       " 1.0461356282697085,\n",
       " 1.0460801437583167,\n",
       " 1.046566993143214,\n",
       " 1.0465574362248453,\n",
       " 1.0465460978682077,\n",
       " 1.0468011593043818,\n",
       " 1.046665754728132,\n",
       " 1.0467544296312288,\n",
       " 1.046619938419754,\n",
       " 1.0466040810469002,\n",
       " 1.047027879045558,\n",
       " 1.0471641515521197,\n",
       " 1.0471805841650816,\n",
       " 1.0472054419441033,\n",
       " 1.047261702272666,\n",
       " 1.0473632659921703,\n",
       " 1.0471706247008585,\n",
       " 1.0472481526087598,\n",
       " 1.046920075676818,\n",
       " 1.0468803330308838,\n",
       " 1.0471202827610837,\n",
       " 1.0470370678426544,\n",
       " 1.0469126628636796,\n",
       " 1.0469197310412917,\n",
       " 1.047055117223787,\n",
       " 1.0467981063757623,\n",
       " 1.0469888536160816,\n",
       " 1.0471161464037295,\n",
       " 1.0474094640896872,\n",
       " 1.0474671855037654,\n",
       " 1.0472175495649383,\n",
       " 1.0473443388849761,\n",
       " 1.0475426254835998,\n",
       " 1.0477875151522427,\n",
       " 1.0477433193454055,\n",
       " 1.047612936588228,\n",
       " 1.0475697149092296,\n",
       " 1.04714873781191,\n",
       " 1.0470093697759932,\n",
       " 1.0470931255653426,\n",
       " 1.0472122216676747,\n",
       " 1.0475282090265723,\n",
       " 1.047316936941931,\n",
       " 1.0475042468702909,\n",
       " 1.0477050853095293,\n",
       " 1.047609494302368,\n",
       " 1.0476537995218864,\n",
       " 1.0473562469001496,\n",
       " 1.0471618820405346,\n",
       " 1.0468752379292492,\n",
       " 1.0467577679344835,\n",
       " 1.0469191730808804,\n",
       " 1.0466549735535424,\n",
       " 1.046487412554658,\n",
       " 1.0463548902723387,\n",
       " 1.0462378003349344,\n",
       " 1.0464636099592932,\n",
       " 1.046676215927586,\n",
       " 1.0467544969008424,\n",
       " 1.0469691743346352,\n",
       " 1.0471517000952544,\n",
       " 1.047193397160347,\n",
       " 1.0472930052135594,\n",
       " 1.047124131889978,\n",
       " 1.0470060457004318,\n",
       " 1.0469364535599763,\n",
       " 1.0466649188013086,\n",
       " 1.0465954115767815,\n",
       " 1.0469255774384625,\n",
       " 1.0466631371917288,\n",
       " 1.0469100366866657,\n",
       " 1.0468822080955074,\n",
       " 1.0469550609974834,\n",
       " 1.0469454297911203,\n",
       " 1.0470769224167766,\n",
       " 1.0469572862389382,\n",
       " 1.0469102744617866,\n",
       " 1.0471272404416756,\n",
       " 1.0473203401887414,\n",
       " 1.047440580810616,\n",
       " 1.0477681612370322,\n",
       " 1.0479247012943198,\n",
       " 1.0479503633793295,\n",
       " 1.0481364630957968,\n",
       " ...]"
      ]
     },
     "execution_count": 7,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "args = Arguments(if_on_policy=True)\n",
    "args.agent = AgentPPO()\n",
    "\n",
    "#choose environment\n",
    "args.env = StockTradingEnv(ary = ary, stock_dim = 30, if_train=True)\n",
    "args.env_eval = StockTradingEnv(ary = ary, stock_dim = 30, if_train=False)\n",
    "args.net_dim = 2 ** 9 # change a default hyper-parameters\n",
    "args.batch_size = 2 ** 8\n",
    "args.break_step = int(5e5)\n",
    "\n",
    "train_and_evaluate(args)\n",
    "\n",
    "env = StockTradingEnv(ary=ary, stock_dim=30 ,if_train=False)\n",
    "args = Arguments(if_on_policy=True)\n",
    "args.agent = AgentPPO()\n",
    "args.env = StockTradingEnv(ary=ary, stock_dim = 30, if_train=False)\n",
    "args.if_remove = False\n",
    "args.cwd = './AgentPPO/Stock_wrds-v1_0'\n",
    "args.init_before_training()\n",
    "\n",
    "env.draw_cumulative_return(args, torch)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "dqqcZhY3DTXa"
   },
   "source": [
    "![cumulative_return.jpg]()"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "include_colab_link": true,
   "name": "eRL_demo_StockTrading.ipynb",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6rc1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
